home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / nevow / jsutil.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-03-23  |  4KB  |  112 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from twisted.python.procutils import which
  5. from twisted.python.util import sibpath
  6. import nevow
  7. from nevow.athena import LivePage, allJavascriptPackages, JSModule
  8. _TEST_BOOTSTRAP = LivePage.BOOTSTRAP_MODULES[:]
  9. _TEST_BOOTSTRAP.insert(_TEST_BOOTSTRAP.index('Divmod.Runtime'), 'Divmod.MockBrowser')
  10. _DUMMY_MODULE_NAME = 'ConsoleJSTest'
  11.  
  12. def getDependencies(fname, ignore = [], bootstrap = _TEST_BOOTSTRAP, packages = None):
  13.     """
  14.     Get the javascript modules that the code in the file with name C{fname}
  15.     depends on, recursively
  16.  
  17.     @param fname: javascript source file name
  18.     @type fname: C{str}
  19.  
  20.     @param ignore: names of javascript modules to exclude from dependency list
  21.     @type ignore: sequence
  22.  
  23.     @param bootstrap: names of javascript modules to always include, regardless
  24.     of explicit dependencies (defaults to L{LivePage}'s list of bootstrap
  25.     modules, plus the mock browser implementation.)
  26.     @type boostrap: sequence
  27.  
  28.     @param packages: all javascript packages we know about.  defaults to the
  29.     result of L{allJavascriptPackages}
  30.     @type packages: C{dict}
  31.  
  32.     @return: modules included by javascript in file named C{fname}
  33.     @rtype: dependency-ordered list of L{JSModule} instances
  34.     """
  35.     if packages is None:
  36.         packages = allJavascriptPackages()
  37.     
  38.     bootstrapModules = _[1]
  39.     packages[_DUMMY_MODULE_NAME] = fname
  40.     module = JSModule(_DUMMY_MODULE_NAME, packages)
  41.     return [] + _[2]
  42.  
  43.  
  44. def findJavascriptInterpreter():
  45.     '''
  46.     Return a string path to a JavaScript interpreter if one can be found in
  47.     the executable path. If not, return None.
  48.     '''
  49.     for script in [
  50.         'smjs',
  51.         'js']:
  52.         _jsInterps = which(script)
  53.         if _jsInterps:
  54.             return _jsInterps[0]
  55.     
  56.  
  57.  
  58. def generateTestScript(fname, after = {
  59.     'Divmod.Base': ('Divmod.Base.addLoadEvent = function() {};',) }, dependencies = None):
  60.     '''
  61.     Turn the contents of the Athena-style javascript test module in the file
  62.     named C{fname} into a plain javascript script.  Recursively includes any
  63.     modules that are depended on, as well as the utility module
  64.     nevow/test/testsupport.js.
  65.  
  66.     @param fname: javascript source file name
  67.     @type fname: C{str}
  68.  
  69.     @param after: mapping of javascript module names to sequences of lines of
  70.     javascript source that should be injected into the output immediately
  71.     after the source of the named module is included
  72.     @type after: C{dict}
  73.  
  74.     @param dependencies: the modules the script depends on.  Defaults to the
  75.     result of L{getDependencies}
  76.     @type dependencies: dependency-ordered list of L{JSModule}
  77.     instances
  78.  
  79.     @return: converted javascript source text
  80.     @rtype: C{str}
  81.     '''
  82.     if dependencies is None:
  83.         dependencies = getDependencies(fname)
  84.     
  85.     
  86.     load = lambda fname: 'load(%r);' % (fname,)
  87.     initialized = { }
  88.     js = [
  89.         load(sibpath(nevow.__file__, 'test/testsupport.js'))]
  90.     for m in dependencies:
  91.         segments = m.name.split('.')
  92.         if segments[-1] == '__init__':
  93.             segments = segments[:-1]
  94.         
  95.         initname = '.'.join(segments)
  96.         if initname not in initialized:
  97.             initialized[initname] = 1
  98.             if '.' in initname:
  99.                 prefix = ''
  100.             else:
  101.                 prefix = 'var '
  102.             js.append('%s%s = {};' % (prefix, initname))
  103.         
  104.         js.append(load(m.mapping[m.name]))
  105.         if m.name in after:
  106.             js.extend(after[m.name])
  107.             continue
  108.     
  109.     js.append(file(fname).read())
  110.     return '\n'.join(js)
  111.  
  112.